<template>
  <view>
    <my-search-bar></my-search-bar>
    <!--  轮播图 -->
    <view>
      <swiper autoplay interval="1600" circular indicator-dots>
        <swiper-item v-for="item in swiperList" :key="item.goods_id">
          <image :src="item.image_src" mode="scaleToFill"></image>
        </swiper-item>
      </swiper>
    </view>
    <!-- 导航菜单 -->
    <view class="nav-list">
      <view v-for="item in catitems" :key="item.name">
        <img
          class="nav-img"
          @click="navClick(item.name)"
          :src="item.image_src"
          alt=""
        />
      </view>
    </view>

    <!-- 楼层数据 -->
    <view v-for="item in floorList" :key="item.floor_title.name">
      <!-- 标题部分 -->
      <image class="floor-title" :src="item.floor_title.image_src"> </image>
      <!-- 内容部分 -->
      <view class="floor-img-box">
        <!-- 左边的图片 -->
        <view>
          <navigator :url="item.product_list[0].navigator_url">
            <image
              mode="widthFix"
              :src="item.product_list[0].image_src"
              :style="{ width: item.product_list[0].image_width + 'rpx' }"
            ></image>
          </navigator>
        </view>
        <!-- 右边的图片 -->
        <view class="right-img-box">
          <navigator
            :url="subitem.navigator_url"
            v-for="(subitem, index) in item.product_list"
            :key="subitem.name"
          >
            <image
              :src="subitem.image_src"
              v-show="index > 0"
              :style="{ width: subitem.image_width + 'rpx' }"
              mode="widthFix"
            ></image>
          </navigator>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      swiperList: [],
      catitems: [],
      floorList: [], //  楼层的数据列表
    };
  },
  onLoad() {
    this.getSwiperList();
    this.getCatitemsData();
    this.getFloorList();
  },
  methods: {
    async getSwiperList() {
      const res = await uni.$request({
        url: "home/swiperdata",
      });
      //   console.log('res', res)
      if (res.meta.status === 200) {
        this.swiperList = res.message;
      }
    },
    async getCatitemsData() {
      const res = await uni.$request({
        url: "home/catitems",
      });
      //   console.log("res", res);
      if (res.meta.status === 200) {
        this.catitems = res.message;
      }
    },
    // 点击菜单
    navClick(name) {
      if (name === "分类") {
        uni.switchTab({ url: "/pages/category/index" });
      }
    },
    async getFloorList() {
      const res = await uni.$request({
        url: "home/floordata",
      });
      //   console.log("res:", res);
      if (res.meta.status === 200) {
        if (res.meta.status === 200) {
          res.message.forEach((item) => {
            item.product_list.forEach((subitem) => {
              subitem.navigator_url =
                "/subpkg/goods-list/index?" +
                subitem.navigator_url.split("?")[1];
            });
          });
        }

        this.floorList = res.message;
      }
    },
  },
};
</script>

<style lang="scss" scoped>
swiper {
  height: 400rpx;

  .swiper-item,
  image {
    width: 100%;
    height: 100%;
  }
}
.nav-list {
  display: flex;
  justify-content: space-around;
  margin: 15px 0;
  flex-wrap: nowrap;

  .nav-img {
    width: 128rpx;
    height: 140rpx;
  }
}
.floor-title {
  height: 60rpx;
  width: 100%;
  display: flex;
}
.right-img-box {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
}
.floor-img-box {
  display: flex;
  padding-left: 10rpx;
}
</style>
